#include <stdio.h>

#define MAXLINE 1000    /* maximum input line size */
#define TABSTOP 8       /* number of columns before a tab stop */

int getline(char s[], int lim);
void detab(char s[], int ts, int lim);

/* detab:  replaces tabs in input with proper number of blanks */
int main(void){
    int len;               /* current line length*/
    char line[MAXLINE];    /* current input line */
    
    while((len = getline(line, MAXLINE)) > 0){
	detab(line, TABSTOP, MAXLINE);
	printf("%s", line);
    }
    return 0;
}

/* getline:  read a line into s, return length */
int getline(char s[], int lim){
    int c, i;

    for(i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
	s[i] = c;
    if(c == '\n'){
	s[i] = c;
	++i;
    }
    s[i] = '\0';
    return i;
}

void detab(char s[], int ts, int lim){
    int i, j, k;
    char tmp[lim];

    for(i=0, j=0; j<lim-1 && s[i]!='\0'; ++i, ++j){
	if(s[i]=='\t'){
	    for(k=0; j+k<lim-1 && k<i%ts; ++k)
		tmp[j+k]=' ';
	    j+=k;
	}
	else
	    tmp[j]=s[i];
    }
    
    for(i=0; i<j; ++i)
	s[i]=tmp[i];

    s[i+1]='\0';
}
